package com.baiyi.homeui.hshomeui.util;

import android.content.Context;
import android.os.PowerManager;

public class ScreenController {
    private PowerManager powerManager;
    private PowerManager.WakeLock wakeLock;
    private String TAG = "ScreenController";
    public ScreenController(Context context) {
        powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "MyWakeLock");
    }

    //亮屏
    public void acquireScreenWakeLock() {
        SLog.d(TAG,"acquireScreenWakeLock  isHeld"+wakeLock.isHeld());
        if (wakeLock != null && !wakeLock.isHeld()) {
            wakeLock.acquire();
            SLog.d(TAG,"wakeLock.acquire");
        }
    }
    //息屏
    public void releaseScreenWakeLock() {
        SLog.d(TAG,"releaseScreenWakeLock  isHeld "+wakeLock.isHeld());
        if (wakeLock != null) {
            wakeLock.release();
            SLog.d(TAG,"wakeLock.release");
        }
    }

    public boolean isScreenOn(){

        if (powerManager != null) {
            boolean isScreenOn = powerManager.isScreenOn();
            SLog.d(TAG,"isScreenOn--"+isScreenOn);
            return isScreenOn;
        }

        return false;
    }
}
